require(['gaodeMap'], function () {
    var polygonOrCircle,
        infoWindow,
        areaAr = [];

    window.showData = function (rowIds) {
        map.clearMap();

        $.ajaxExt({
            url: "/baseLineBlackRel/getBlackSpotsByIds.htm",
            data: {'ids': rowIds.toString()}
        }).done(function (list) {
            //勾选的黑点进行展示
            //console.log(list);

            //debugger;

            $.each(areaAr, function (i, item) {
                item.setMap(null);
            });
            areaAr = [];

            if (infoWindow) {
                infoWindow.setMap(null);
            }

            if (list) {
                var data;
                for (var i = 0; i < list.length; i++) {
                    data = list[i];

                    //console.log(data);

                    var params = [];
                    if (data.fencType == 1) {
                        var item;
                        for (var j = 0; j < data.list.length; j++) {
                            item = data.list[j];
                            params.push([item.fencLgt, item.fencLtt]);
                            if (j == 0) {
                                //map.setMapCenterAndLevel(item.fencLgt, item.fencLtt, 12);
                            }
                        }

                        polygonOrCircle = new AMap.Polygon($.extend({
                            map: map,
                            path: params
                        }, defaultConfig));

                        polygonOrCircle.on('mouseover', markerClick);
                        var areaRoad = data.hasOwnProperty('areaRoad') == true ? data.areaRoad : '未知';
                        polygonOrCircle.content = '<p>黑点名称：' + data.blackName + '</p>' +
                            '<p>黑点性质：' + data.blackNature + '</p><p>危险度：' + data.dangerDegree + '</p><p>区域路段：' + areaRoad + '</p>';
                        polygonOrCircle.position = params[0];


                    } else {
                        var center = [data.coreLgt, data.coreLtt];
                        polygonOrCircle = new AMap.Circle($.extend({
                            center: center,// 圆心位置
                            radius: data.coreRadius
                        }, defaultConfig));
                        //map.setMapCenterAndLevel(data.coreLgt, data.coreLtt, 12);

                        polygonOrCircle.on('mouseover', markerClick);
                        var areaRoad = data.hasOwnProperty('areaRoad') == true ? data.areaRoad : '未知';
                        polygonOrCircle.content = '<p>黑点名称：' + data.blackName + '</p>' +
                            '<p>黑点性质：' + data.blackNature + '</p><p>危险度：' + data.dangerDegree + '</p><p>区域路段：' + areaRoad + '</p>';
                        polygonOrCircle.position = center;


                    }
                    polygonOrCircle.setMap(map);
                    areaAr.push(polygonOrCircle);
                }
            }
            mapObj.mapFitView();
            showMarkerInfo(areaAr[0]);
        });
    }

    //地图设置开始  ----------------------------------------------------
    
    // 动态设置高度
    $('#iCenter').height($(window.parent).height() * 0.85);

    //地图
    var mapObj = new MapGaoDe(107.49023438, 36.24427318, 4);
    map = mapObj.map;

    var defaultConfig = {
        // strokeColor: "#1791fc",
        strokeColor: "#ff0000",
        strokeOpacity: 0.8,
        strokeWeight: 2,
        // fillColor: "#1791fc",
        fillColor: "#ff0000",
        fillOpacity: 0.35,
        strokeStyle: "solid",
        strokeDasharray: [10, 5]
    };

    /**
     * 标记点击显示信息
     * @param e 目标元素
     */
    function markerClick(e) {
        if (infoWindow) {
            infoWindow.setMap(null);
        }
        infoWindow = new AMap.InfoWindow({
            content: e.target.content
        });
        infoWindow.open(map, e.target.position);
    }

    /**
     * 显示标记信息
     * @param circle
     */
    function showMarkerInfo(areaAr) {
        if (infoWindow) {
            infoWindow.setMap(null);
        }
        infoWindow = new AMap.InfoWindow({
            content: areaAr.content
        });
        infoWindow.open(map, areaAr.position);
    }

    //地图设置结束  ----------------------------------------------------

});